package com.teach.javafxclient.controller.base;

import com.teach.javafxclient.Globalvar;
import com.teach.javafxclient.MainApplication;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import kong.unirest.json.JSONArray;

import java.io.IOException;

/**
 * @author Liang Jianlin
 * @date 2024-05-02 01:41
 */
public class CourseInfoDetailController {
    @FXML
    public Label term;
    @FXML
    public Label college;
    @FXML
    public Label credit;
    @FXML
    public Label assessment;
    @FXML
    public Label introduction;
    @FXML
    public Label time;
    @FXML
    public Text courseLocation;
    @FXML
    public HBox edit;
    public ImageView courseTable;
    public VBox floatPane;
    private JSONArray timeArray;

    public void initialize(){
        if(!Globalvar.userRole.equals("ADMIN")){
            edit.setManaged(false);
            edit.setVisible(false);
        }
        floatPane.setVisible(false);
        floatPane.setVisible(false);
        floatPane.setDisable(true);
        courseTable.setOnMouseClicked(e->{
            floatPane.setManaged(!floatPane.isManaged());
            floatPane.setVisible(!floatPane.isVisible());
        });
    }
    public void setTime(JSONArray timeArray) throws IOException {
        this.timeArray = timeArray;
        FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("base/course-table.fxml"));
        Parent root = fxmlLoader.load();
        CourseTableController CTC = fxmlLoader.getController();
        CTC.set(timeArray);
        floatPane.getChildren().add(root);
    }
}
